package dataset.generation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;

import org.mitre.jawb.io.SgmlElement;

public class SgmledSegment extends Segment {

	private ArrayList<SgmlElement> sgmlElements;
	private List<SgmlElement> totalSgmlElements; //sorted by order of appearance
	private Hashtable<Integer, SgmlElement> orders;
	
	public SgmledSegment(String text, int offset, List<SgmlElement> containedSgmlElements) {
		super(text, offset);
		
		orders = new Hashtable<Integer, SgmlElement>();
		
		totalSgmlElements = containedSgmlElements;
		
		sgmlElements = new ArrayList<SgmlElement>();
	}
	
	public void addSgmlElement(SgmlElement element, int order){
		
		orders.put(order, element);
				
		sgmlElements.add(element);
		
		Collections.sort(sgmlElements, new Comparator<SgmlElement>() {

			@Override
			public int compare(SgmlElement arg0, SgmlElement arg1) {
				
				return Integer.valueOf(arg0.getStart()).compareTo(arg1.getStart());
				
			}
		});
		
	}
	
	public String toString(){
		
		return new String(super.toString() + " - " + getString());
		
	}

	private String getString() {
		
		String ret = "";
		
		for (SgmlElement element : sgmlElements) {
			
			ret += element.toString();
			
		}
		
		return ret;
		
	}
	
	public List<SgmlElement> getSgmlElements(){
		return totalSgmlElements;
	}

	public SgmlElement getRelevantSgmlElement(int order) {
		return orders.get(order);
	}

	
	
}
